<template>
  <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="90%" :showOkBtn="false">

    <vxe-grid ref="tableRef" v-bind="gridOptions" :style="{height: (contentHeight*0.85)+'px'}">
      <template #toolbar_buttons>

      </template>

    </vxe-grid>


  </BasicDrawer>
</template>
<script lang="ts" setup>
import {ref, computed, unref, reactive} from 'vue';
import { BasicForm, useForm, ApiSelect } from '@/components/Form';
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import util from "@/utils/util";

import { pmcOemItems,oemMaterialRefList,orderBomList} from '@/api/heng/stock';
import { useMessage } from "@/hooks/web/useMessage";
import { useUserStore } from "@/store/modules/user";
import {BasicTableProps, VxeTableDefines} from "@/components/VxeTable";
import {itemColumns, vxeTableColumns} from './role.data';
import { notInOrderTable} from "@/api/heng/dkn";

const userStore = useUserStore();


const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const dataList = ref({});
const { createMessage } = useMessage();
const contentHeight = ref(window.innerHeight);

const id = ref("");

const tableRef = ref();


const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
  //打开弹层后的回调
  // setDrawerProps({ confirmLoading: false });
  // 需要在setFieldsValue之前先填充treeData，否则Tree组件可能会报key not exist警告
  // if (unref(treeData).length === 0) {
  //   treeData.value = (await getMenuList()) as any as TreeItem[];
  // }
  isUpdate.value = !!data?.isUpdate;
  id.value = "";
  dataList.value=data;
  tableRef.value.commitProxy('reload');

});

const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  border: true,
  showOverflow: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: itemColumns,
  filterConfig: {
    remote: true,
  },

  showFooter: true,

  toolbarConfig: {
    enabled: false,
  },
  formConfig: {
    enabled: false,
  },
  pagerConfig: {
    // pageSize: 20,
  },
  proxyConfig: {
    props: {
      result: 'data.list',
      list: 'data.list',
      total: 'data.totalResult',
      message: 'message',
    },
    filter: true,
    ajax: {
      query: ({ page, form, filters }) => {
        return findPageList(page, form, filters);
      },
    },
  },
});



function findPageList(page, form, filterList?: VxeTableDefines.FilterCheckedParams<any>[]) {
  let json = {};
  if (filterList && filterList.length) {
    filterList.forEach((e) => {
      const value = e.datas[0];
      let field = e.field;
      json[field ] = value;
    });
  }
  // console.log("----json:", json);
  // ywApproveList xftList
  return notInOrderTable({
    page: page.currentPage,
    pageSize: page.pageSize,
    ...form,
    ...json,
  });
}






const getTitle = computed(() => (!unref(isUpdate) ? '查看未入库的备货订单' : '查看未入库的备货订单'));




</script>
